import os
import sys
from cvio import cvio

def main_merge_empty_wrong(src):
    # 对筛选误识别之后的数据进行处理，将每个错误标签的 [] 符号去掉，两个不通的标签中间用-隔开
    anns = cvio.load_ext_list(src, recursive=True)
    
    for path in anns:
        info = cvio.load_ann(path)
        print(path)
        for shape in info['shapes']:
            label = shape['label']
            if '[]' in label:
                label = label.replace('[]', '').replace('[', '').replace(']', '')
                shape['label'] = label
            else:
                label = label[1:-1].replace('][', '-')
                shape['label'] = label
        cvio.write_ann(info, path)


main_merge_empty_wrong(r'G:\data\datasets\drink\pesi\ai\wrong')
